import wepy from 'wepy'
import Dialog from '../../assets/vant/dialog/dialog';
import Toast from '../../assets/vant/toast/toast';
export default class extends wepy.mixin {
	data = {
		//   默认收获地址
		getaddressDeftInfo: {},
		// 用户id
		userId: wepy.getStorageSync('userId'),
		// 购物车id
		cart_id_list: '',
		// 数量
		cart_num_list: '',
		orderListInfo: [],
		// 单商品订单信息
		goods_info: {},
		state: '',
		// 单商品信息
		goodInfo: {},
		title: '',
		imgPath: '',
		price: '',
		//商品关联id
		seckillGoodId: '',
		momun: '',
		manjianMoney: '',
		// 自提
		qhType: '0',
		communityId: '',
		// 单商品优惠信息
		youhuiInfo: {
			totalPrice: "0.00",
			youhuiTotal: "0.00",
			orderFreight: "0.00",
			youhuiFreight: "0.00",
			wuyeDikou: "0.00",
		},
		addre: {
			"area": "",
			"areaId": "",
			"building": "",
			"buildingId": "",
			"community": "",
			"communityId": "",
			"houseNumber": "",
			"houseNumberId": "",
			"id": "",
			"isDefault": "",
			"linkPhone": "",
			"reName": "",
			"unit": "",
			"unitId": ""
		},
		show2: false,
		mingzi: '',
		telnumber: '',
		xiaoquList: [],
		columns2: [],
		quyu: '请选择小区',
		// 小区id
		xid: '',
		ziTiInfo: {},
		passageInfo: {},
		// 购物车优惠信息
		cartyouhuiInfo: {},
		cartyou: {
			youhuiPrice: "0.00",
			orderFreight: "0.00",
			totalPrice: "0.00",
			youhuiFreight: "0.00",
			wuyefei: "0.00"
		},
		// 用户自提信息
		userZiti: {},
		disabled: false,
		rchecked: false,
		rdisabled: false,
		sendsgoods: '',
		disjinyong: false,
		jifen: '',
		hunhezhifu: false,
		jiaoyimima: '',
		isPoint: '',
		payType: '0',
		tabsp: "0",
		//收货地址
		shouhuo: "",
		sanareaId:'',
		shengId:'',
		shiId:'',
		quId:''
	}
	methods = {
		//收货地址选择
		addressqie(i) {
			this.tabsp = i;
			if (i == 0) { //到家
				this.qhType = '0'
				this.xiaoquList = [];
				if (this.state == '1') { //单商品进入不自提
					this.getAddressdefalt(0)
				} else { //购物车进入不自提
					this.getAddressdefalt(1)
				}
			} else if (i == 1) { //自提
				this.qhType = '1'
				this.xiaoquList = [];
				this.getuserId()
				this.getxiaoquList()
			} else if (i == 2) { //收货
				this.qhType = '0';
				this.xiaoquList = [];
				if (this.state == '1') { //单商品进入不自提
					this.getDefaultDelivery(0)
				} else { //购物车进入不自提
					this.getDefaultDelivery(1)
				}
			}
		},
		//单商品是否使用R点
		rkuangChange(e) {
			this.rchecked = e.detail
			if (e.detail) {
				this.goodInfo.payType = '1';
				this.$apply()
				this.getmoneyInfo()
			} else {
				this.goodInfo.payType = '0';
				this.$apply()
				this.getmoneyInfo()
			}
		},
		//购物车进入是否使用R点
		shopprkuangChange(e) {
			this.rchecked = e.detail
			if (e.detail) {
				this.payType = '1'
				this.$apply()
				this.getcartzitiMoney()
			} else {
				this.payType = '0'
				this.$apply()
				this.getcartzitiMoney()
			}
		},
		//到家
		editaddress() {
			wepy.navigateTo({
				url: '../../pages/editUser/edituser?xiugai=' + 1,
			})
		},
		//收货
		shouhuodizhi() {
			wepy.navigateTo({
				url: '../../pages/shouhuoaddress/shouhuoaddress'
			})
		},
		ggvbn() {
			wepy.navigateTo({
				url: '../../pages/shouhuolist/shouhuolist'
			})
		},
		plot() {
			this.show2 = true
		},
		onCancel2() {
			this.show2 = false
		},
		onConfirm2(event) {
			this.show2 = false
			this.quyu = event.detail.value
			for (var i = 0; i < this.xiaoquList.length; i++) {
				if (this.xiaoquList[i].name == this.quyu) {
					this.xid = this.xiaoquList[i].id
					this.addre.communityId = this.xiaoquList[i].id;
				}
			}
			if (this.state == '1') { //单商品进入自提
				this.getmoneyInfo()
			} else { //购物车进入自提
				this.getcartzitiMoney()
			}
		},
		namestate(e) {
			this.mingzi = e.detail.value
		},
		//校验自提手机号
		handletel(e) {
			console.log(e.detail)
			var phonetel = /^1[0-9]{10}$/;
			if (!phonetel.test(e.detail.value)) {
				this.telnumber = e.detail.value
				return Toast.fail('请输入正确的联系电话')
			} else {
				this.telnumber = e.detail.value
			}
		},
		onClickHide() {
			this.hunhezhifu = false;
			this.jiaoyimima = "";
		},
		// 去支付
		async onSubmit() {
			const res = await wepy.getNetworkType({
				//检查网络状态
			})
			if (res.networkType == 'none') {
				Toast.fail('请检查网络设置后重试')
			} else {
				var phonetel = /^1[0-9]{10}$/;
				if (this.qhType != "0") { //自提
					if (this.xid == '') {
						return Toast.fail('请填写小区信息')
					} else if (this.mingzi == '') {
						return Toast.fail('请填写姓名')
					} else if (!phonetel.test(this.telnumber)) {
						return Toast.fail('请填写正确的联系电话')
					} else {
						if (this.show2) {
							return Toast.fail('请先确认自提地址')
						} else {
							if (this.goodInfo.payType == 3) {
								console.log("选择了全积分支付")
								if (this.jifen.payPwd == '') {
									Dialog.confirm({
											title: '交易密码',
											message: '您还没有设置交易密码,是否设置',
											confirmButtonText: '设置'
										})
										.then(() => {
											wepy.navigateTo({
												url: '../../pages/Password/password?state=' + 0
											});
										})
										.catch(() => {
											// on cancel
										});
								} else {
									this.hunhezhifu = true;
									this.$apply()
								}
							} else if (this.goodInfo.payType == 4) {
								console.log("选择了积分+现金支付")
								this.zhifus()
							} else if (this.goodInfo.payType == 0 && this.payType == 0) {
								console.log("普通商品人民币支付")
								this.zhifus()
							} else if (this.goodInfo.payType == 1) { //单商品
								if (this.youhuiInfo.totalPrice == 0) { //单商品全R点支付
									if (this.jifen.payPwd == '') {
										Dialog.confirm({
												title: '交易密码',
												message: '您还没有设置交易密码,是否设置',
												confirmButtonText: '设置'
											})
											.then(() => {
												wepy.navigateTo({
													url: '../../pages/Password/password?state=' + 0
												});
											})
											.catch(() => {
												// on cancel
											});
									} else {
										this.hunhezhifu = true;
										this.$apply()
									}
								} else { //R点+现金支付
									this.zhifus()
								}
							} else if (this.payType == 1 || this.payType == 0) { //购物车
								if (this.cartyou.totalPrice == 0) { //购物车全R点支付
									if (this.jifen.payPwd == '') {
										Dialog.confirm({
												title: '交易密码',
												message: '您还没有设置交易密码,是否设置',
												confirmButtonText: '设置'
											})
											.then(() => {
												wepy.navigateTo({
													url: '../../pages/Password/password?state=' + 0
												});
											})
											.catch(() => {
												// on cancel
											});
									} else {
										this.hunhezhifu = true;
										this.$apply()
									}
								} else { //R点+现金支付
									this.zhifus()
								}
							}
						}
					}
				} else { //不自提
					if (this.addre.id == '') {
						return Toast.fail('暂无收货地址');
					} else if (this.money <= 0) {
						return Toast.fail('订单金额不能为空')
					} else {
						if (this.goodInfo.payType == 3) {
							console.log("选择了全积分支付")
							if (this.jifen.payPwd == '') {
								Dialog.confirm({
										title: '交易密码',
										message: '您还没有设置交易密码,是否设置',
										confirmButtonText: '设置'
									})
									.then(() => {
										wepy.navigateTo({
											url: '../../pages/Password/password?state=' + 0
										});
									})
									.catch(() => {
										// on cancel
									});
							} else {
								this.hunhezhifu = true;
								this.$apply()
							}
						} else if (this.goodInfo.payType == 4) {
							console.log("选择了积分+现金支付")
							this.zhifus()
						} else if (this.goodInfo.payType == 0 && this.payType == 0) {
							console.log("普通商品人民币支付")
							this.zhifus()
						} else if (this.goodInfo.payType == 1) { //单商品
							if (this.youhuiInfo.totalPrice == 0) { //单商品全R点支付
								if (this.jifen.payPwd == '') {
									Dialog.confirm({
											title: '交易密码',
											message: '您还没有设置交易密码,是否设置',
											confirmButtonText: '设置'
										})
										.then(() => {
											wepy.navigateTo({
												url: '../../pages/Password/password?state=' + 0
											});
										})
										.catch(() => {
											// on cancel
										});
								} else {
									this.hunhezhifu = true;
									this.$apply()
								}
							} else { //R点+现金支付
								this.zhifus()
							}
						} else if (this.payType == 1 || this.payType == 0) { //购物车
							if (this.cartyou.totalPrice == 0) { //购物车全R点支付
								if (this.jifen.payPwd == '') {
									Dialog.confirm({
											title: '交易密码',
											message: '您还没有设置交易密码,是否设置',
											confirmButtonText: '设置'
										})
										.then(() => {
											wepy.navigateTo({
												url: '../../pages/Password/password?state=' + 0
											});
										})
										.catch(() => {
											// on cancel
										});
								} else {
									this.hunhezhifu = true;
									this.$apply()
								}
							} else { //R点+现金支付
								this.zhifus()
							}
						}
					}
				}
			}
		},
		bindKeyInput(event) {
			console.log(event)
			this.jiaoyimima = event.detail.value
		},
		//全积分或全R点支付
		async jifendian() {
			if (this.jifen.payPwd != '') {
				if (this.jiaoyimima != '') {
					const res = await wepy.post('baseRest/checkTradePwd', {
						memberId: wepy.getStorageSync('userId'),
						opwd: this.jiaoyimima,
					})
					console.log(res)
					if (res.data.state == 1) {
						this.hunhezhifu=false;
						this.$apply()
						this.zhifus()
					} else {
						Toast.fail(res.data.message);
					}
				} else {
					Toast.fail('请输入交易密码');
				}
			} else {
				Toast.fail('请先设置交易密码');
			}
		}
	}
	onLoad(options) {
		this.state = options.state;
		if (this.state == '1') { //单商品进入
			console.log("单商品进入")
			this.getAddressdefalt(0)
			//单商品订单信息
			console.log('单商定', this.$parent.globalData.goods_info)
			this.goods_info = this.$parent.globalData.goods_info
			this.$parent.globalData.goods_info = {}
			//单商品信息
			console.log('单商新', this.goodInfo = this.$parent.globalData.goodInfo)
			this.goodInfo = this.$parent.globalData.goodInfo
			this.$parent.globalData.goodInfo = {}
			if (this.$parent.globalData.seckillGoodId != '') {
				this.seckillGoodId = this.$parent.globalData.seckillGoodId
			}
			this.$parent.globalData.seckillGoodId = ""
			console.log('商品关联id12345679', this.seckillGoodId)
		} else { //购物车进入
			console.log("购物车进入")
			if (this.cart_id_list != null) {
				this.cart_id_list = options.cart_id_list
				this.cart_num_list = options.cart_num_list
				this.isPoint = options.isPoint
				if (this.tabsp == 0) {
					this.orderList();
					this.getAddressdefalt(1)
				} else if (this.tabsp == 1) {
					this.getAddressdefalt(1)
				} else if (this.tabsp == 2) {
					this.orderList();
					this.getDefaultDelivery(1)
				}
			}
		}
	}
	onShow() {
		this.disjinyong = false;
		//获取可用R点
		this.jifenlist();
		if (this.state == '1') {
			console.log("单商品")
			if (this.tabsp == 0) {
				this.getAddressdefalt(0)
			} else if (this.tabsp == 2) {
				this.getDefaultDelivery(0)
			} else if (this.tabsp == 1) {
				this.getAddressdefalt(0)
			}
		} else {
			console.log("购物车")
			if (this.tabsp == 0) {
				if (this.cart_id_list != '' && this.cart_num_list != '') {
					console.log("获取订单信息")
					this.orderList();
					this.getAddressdefalt(1)
				}
			} else if (this.tabsp == 2) {
				this.orderList();
				this.getDefaultDelivery(1)
				console.log("收货地址")
			} else if (this.tabsp == 1) {
				if (this.cart_id_list != '' && this.cart_num_list != '') {
					console.log("获取订单信息")
					this.orderList();
					this.getAddressdefalt(1)
				}
			}
		}
	}
	async zhifus() {
		var that = this
		if (that.state == '1') { //单个商品不自提支付
			console.log("单商品支付")
			if (this.qhType == "0") {
				console.log("111111111")
				if (that.addre.id == '') {
					return Toast.fail('暂无收货地址');
				} else if (that.money <= 0) {
					return Toast.fail('订单金额不能为空')
				} else {
					console.log(that.addre, "单商品不自提支付地址")
					const {
						data: res
					} = await wepy.post('baseRest/saveOrder', {
						memberId: that.userId,
						goods_info: that.goods_info,
						address: that.addre,
						seckillGoodId: that.seckillGoodId,
						qhType: that.qhType,
						payType: that.goodInfo.payType,
						areaId:that.sanareaId
					})
					console.log(res)
					if (res.state != 1) {
						return Toast.fail(res.message)
					} else {
						that.disjinyong = true;
						if (that.youhuiInfo.totalPrice == 0) { //全积分或者全R币支付
							const {
								data: result
							} = await wepy.post('baseRest/orderPay', {
								id: res.data,
								pwd: that.jiaoyimima
							})
							if (result.state != 1) {
								return Toast.fail(result.message)
							} else {
								wepy.redirectTo({
									url: '../../pages/Order/order?i=' + 0,
								})
								return
							}
						} else {
							const {
								data: result
							} = await wepy.post('baseRest/toWechatpay', {
								orderId: res.data,
							})
							if (result.state != 1) {
								return Toast.fail(result.message)
							} else {
								// 调用微信支付接口
								const payResult = await wx
									.requestPayment({
										timeStamp: result.data.timestamp,
										nonceStr: result.data.nonceStr,
										package: result.data.package,
										signType: result.data.signType,
										paySign: result.data.paySign,
									})
									.catch((err) => err)
								// 用户取消了支付
								console.log(payResult, "判断支付状态")
								if (payResult.errMsg === 'requestPayment:fail cancel') {
									Toast.fail('您已取消了支付！')
									wepy.redirectTo({
										url: '../../pages/Order/order?i=' + 1,
									})
									return
								} else {
									wepy.redirectTo({
										url: '../../pages/Order/order?i=' + 0,
									})
									return
								}
							}
						}
					}
				}
			} else {
				console.log("2222222222")
				//单个商品自提
				var phonetel = /^1[0-9]{10}$/;
				if (that.xid == '') {
					return Toast.fail('暂无小区信息')
				} else if (that.mingzi == '') {
					return Toast.fail('请填写姓名')
				} else if (!phonetel.test(that.telnumber)) {
					return Toast.fail('请填写正确的联系电话')
				} else {
					if (that.show2) {
						return Toast.fail('请先确认自提地址')
					} else {
						var phonetel = /^1[0-9]{10}$/;
						if (that.xid == '') {
							return Toast.fail('请填写小区信息')
						} else if (that.mingzi == '') {
							return Toast.fail('请填写姓名')
						} else if (!phonetel.test(that.telnumber)) {
							return Toast.fail('请填写正确的联系电话')
						} else {
							const ziTiInfo = {
								area: '',
								building: '',
								community: that.quyu,
								communityId: that.xid,
								telNumber: that.telnumber,
								userName: that.mingzi,
								buildingId: '',
							}
							const {
								data: res
							} = await wepy.post('baseRest/saveOrder', {
								memberId: that.userId,
								goods_info: that.goods_info,
								address: ziTiInfo,
								seckillGoodId: that.seckillGoodId,
								qhType: that.qhType,
								payType: that.goodInfo.payType,
								areaId:''
							})
							console.log(res)
							if (res.state != 1) {
								return Toast.fail(res.message)
							} else {
								that.disjinyong = true;
								if (that.youhuiInfo.totalPrice == 0) { //全积分或者全R币支付
									const {
										data: result
									} = await wepy.post('baseRest/orderPay', {
										id: res.data,
										pwd: that.jiaoyimima
									})
									if (result.state != 1) {
										return Toast.fail(result.message)
									} else {
										wepy.redirectTo({
											url: '../../pages/Order/order?i=' + 0,
										})
										return
									}
								} else {
									const {
										data: result
									} = await wepy.post('baseRest/toWechatpay', {
										orderId: res.data,
									})
									if (result.state != 1) {
										return Toast.fail(result.message)
									} else {
										// 调用微信支付接口
										const payResult = await wx
											.requestPayment({
												timeStamp: result.data.timestamp,
												nonceStr: result.data.nonceStr,
												package: result.data.package,
												signType: result.data.signType,
												paySign: result.data.paySign,
											})
											.catch((err) => err)
										// 用户取消了支付
										console.log(payResult, "判断支付状态")
										if (payResult.errMsg === 'requestPayment:fail cancel') {
											Toast.fail('您已取消了支付！')
											wepy.redirectTo({
												url: '../../pages/Order/order?i=' + 1,
											})
											return
										} else {
											wepy.redirectTo({
												url: '../../pages/Order/order?i=' + 0,
											})
											return
										}
									}
								}
							}
						}
					}
				}
			}
		} else {
			console.log("购物车支付")
			console.log(that.qhType)
			if (that.qhType == "0") { //购物车不自提
				console.log("111111111")
				if (that.addre.id == '') {
					return Toast.fail('暂无收货地址');
				} else if (that.money <= 0) {
					return Toast.fail('订单金额不能为空')
				} else {
					console.log(that.addre, "购物车不自提支付地址")
					const {
						data: res
					} = await wepy.post('baseRest/saveOrderList', {
						cart_id_list: that.cart_id_list,
						address: that.addre,
						qhType: that.qhType,
						payType: that.payType,
						memberId: that.userId,
						areaId:that.sanareaId
					})
					if (res.state != 1) {
						return Toast.fail(res.message)
					} else {
						that.disjinyong = true;
						if (that.cartyou.totalPrice == 0) { //全R币支付
							const {
								data: result
							} = await wepy.post('baseRest/orderPay', {
								id: res.data,
								pwd: that.jiaoyimima
							})
							if (result.state != 1) {
								return Toast.fail(result.message)
							} else {
								wepy.redirectTo({
									url: '../../pages/Order/order?i=' + 0,
								})
								return
							}
						} else {
							const {
								data: result
							} = await wepy.post('baseRest/toWechatpay', {
								orderId: res.data,
							})
							if (res.state != 1) {
								return Toast.fail(res.message)
							} else {
								const payResult = await wx
									.requestPayment({
										timeStamp: result.data.timestamp,
										nonceStr: result.data.nonceStr,
										package: result.data.package,
										signType: result.data.signType,
										paySign: result.data.paySign,
									})
									.catch((err) => err)
								// 用户取消了支付
								if (payResult.errMsg === 'requestPayment:fail cancel') {
									Toast.fail('您已取消了支付！')
									wepy.redirectTo({
										url: '../../pages/Order/order?i=' + 1,
									})
									return
								} else {
									wepy.redirectTo({
										url: '../../pages/Order/order?i=' + 0,
									})
									return
								}
							}
						}
					}
				}
			} else { //购物车自提
				console.log("购物车自提")
				var phonetel = /^1[0-9]{10}$/;
				if (that.xid == '') {
					return Toast.fail('请填写小区信息')
				} else if (that.mingzi == '') {
					return Toast.fail('请填写姓名')
				} else if (!phonetel.test(that.telnumber)) {
					return Toast.fail('请填写正确的联系电话')
				} else {
					if (that.show2) {
						return Toast.fail('请先确认自提地址')
					} else {
						if (that.xid == '') {
							return Toast.fail('请填写小区信息')
						} else if (that.mingzi == '') {
							return Toast.fail('请填写姓名')
						} else if (!phonetel.test(that.telnumber)) {
							return Toast.fail('请填写正确的联系电话')
						} else {
							const ziTiInfo = {
								area: '',
								building: '',
								community: that.quyu,
								communityId: that.xid,
								telNumber: that.telnumber,
								userName: that.mingzi,
								buildingId: '',
							}
							const {
								data: res
							} = await wepy.post('baseRest/saveOrderList', {
								cart_id_list: that.cart_id_list,
								address: ziTiInfo,
								qhType: that.qhType,
								communityId: that.communityId,
								payType: that.payType,
								memberId: that.userId,
								areaId:''
							})
							if (res.state != 1) {
								return Toast.fail(res.message)
							} else {
								that.disjinyong = true;
								if (that.cartyou.totalPrice == 0) { //全R币支付
									const {
										data: result
									} = await wepy.post('baseRest/orderPay', {
										id: res.data,
										pwd: that.jiaoyimima
									})
									if (result.state != 1) {
										return Toast.fail(result.message)
									} else {
										wepy.redirectTo({
											url: '../../pages/Order/order?i=' + 0,
										})
										return
									}
								} else {
									const {
										data: result
									} = await wepy.post('baseRest/toWechatpay', {
										orderId: res.data,
									})
									console.log(result)
									if (res.state != 1) {
										return Toast.fail(res.message)
									} else {
										// 调用微信支付接口
										const payResult = await wx
											.requestPayment({
												timeStamp: result.data.timestamp,
												nonceStr: result.data.nonceStr,
												package: result.data.package,
												signType: result.data.signType,
												paySign: result.data.paySign,
											})
											.catch((err) => err)
										// 用户取消了支付
										if (payResult.errMsg === 'requestPayment:fail cancel') {
											Toast.fail('您已取消了支付！')
											wepy.redirectTo({
												url: '../../pages/Order/order?i=' + 1,
											})
											return
										} else {
											wepy.redirectTo({
												url: '../../pages/Order/order?i=' + 0,
											})
											return
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	// 获取默认的收货地址
	async getDefaultDelivery(index) {
		const res = await wepy.post('baseRest/getDefaultDelivery', {
			memberId: wepy.getStorageSync('userId'),
		})
		console.log(res, "默认收货地址")
		if (res.statusCode != 200) {
			return Toast.fail('获取数据失败')
		} else {
			var that = this
			if (res.data.data.area) {
				that.shouhuo = res.data.data;
				that.addre.id = res.data.data.id;
				that.addre.reName = res.data.data.reName;
				that.addre.linkPhone = res.data.data.linkPhone;
				that.addre.area = res.data.data.pca + '-' + res.data.data.street;
				that.shengId = res.data.data.province;
				that.shiId = res.data.data.city;
				that.quId = res.data.data.area;
				that.addre.building = '';
				that.addre.buildingId = '';
				that.addre.communityId = '';
				that.addre.houseNumber = '';
				that.addre.houseNumberId = '';
				that.addre.isDefault = '';
				that.addre.areaId='';
				that.sanareaId = res.data.data.area + ',' + res.data.data.city + ',' + res.data.data.province;
				that.addre.unit = '';
				that.addre.community = '';
				that.addre.unitId = '';
				that.$apply()
				//默认不是自提  获取优惠信息
				if (index == 0) {
					this.getmoneyInfo()
				} else {
					this.getcartzitiMoney()
				}
			} else {
				var sspp = {
					"area": "",
					"areaId": "",
					"building": "",
					"buildingId": "",
					"community": "",
					"communityId": "",
					"houseNumber": "",
					"houseNumberId": "",
					"id": "",
					"isDefault": "",
					"linkPhone": "",
					"reName": "",
					"unit": "",
					"unitId": ""
				}
				that.addre = sspp;
				if (this.tabsp == 1) {
					this.qhType = '1'
					this.communityId = this.addre.communityId //小区id
					if (this.state == '1') { //单商品进入自提
						this.getuserId()
						this.getxiaoquList()
					} else { //购物车进入自提
						this.getuserId()
						this.getxiaoquList()
					}
				} else if (this.tabsp == 0) {
					this.qhType = '0'
					this.communityId = ''
					if (this.state == '1') { //单商品进入自提
						this.getuserId() //查询用户是否有自提地址
						this.getxiaoquList()
					} else { //购物车进入自提
						this.getuserId()
						this.getxiaoquList()
					}
				}
				this.$apply()
			}
		}
	}
	// 获取积分
	async jifenlist() {
		const res = await wepy.post('baseRest/getMemberRCoinAndJf', {
			memberId: wepy.getStorageSync('userId'),
		})
		console.log(res, "积分")
		if (res.statusCode != 200) {
			return Toast.fail('获取数据失败')
		}
		this.jifen = res.data.data
		this.$apply()
	}
	// 获取选择收货的地址 但不默认
	async getAddressDetail(id, index) {
		const res = await wepy.post('baseRest/getAddressDetail', {
			id: id,
		})
		console.log('获取选择收货的地址 但不默认', res)
		var that = this
		if (res.statusCode != 200) {
			Toast.fail('获取地址失败')
		}
		if (res.data.data.area) {
			that.addre = res.data.data
			that.$apply()
			//默认不是自提  获取优惠信息
			if (index == 0) {
				this.getmoneyInfo()
			} else {
				this.getcartzitiMoney()
			}
		}
	}
	// 获取默认地址
	async getAddressdefalt(index) {
		const res = await wepy.post('baseRest/getDefaultAddr', {
			memberId: wepy.getStorageSync('userId'),
		})
		console.log('获取默认地址', res)
		if (res.statusCode != 200) {
			Toast.fail('获取地址失败')
		} else {
			var that = this
			if (res.data.data.area) {
				that.addre = res.data.data;
				that.sanareaId='';
				that.$apply()
				//默认不是自提  获取优惠信息
				if (index == 0) {
					this.getmoneyInfo()
				} else {
					this.getcartzitiMoney()
				}
			} else {
				var sspp = {
					"area": "",
					"areaId": "",
					"building": "",
					"buildingId": "",
					"community": "",
					"communityId": "",
					"houseNumber": "",
					"houseNumberId": "",
					"id": "",
					"isDefault": "",
					"linkPhone": "",
					"reName": "",
					"unit": "",
					"unitId": ""
				}
				that.addre = sspp;
				if (this.tabsp == 1) {
					this.qhType = '1'
					this.communityId = this.addre.communityId //小区id
					if (this.state == '1') { //单商品进入自提
						this.getuserId()
						this.getxiaoquList()
					} else { //购物车进入自提
						this.getuserId()
						this.getxiaoquList()
					}
				} else if (this.tabsp == 0) {
					this.qhType = '0'
					this.communityId = ''
					if (this.state == '1') { //单商品进入自提
						this.getuserId() //查询用户是否有自提地址
						this.getxiaoquList()
					} else { //购物车进入自提
						this.getuserId()
						this.getxiaoquList()
					}
				}
				this.$apply()
			}
		}
	}
	// 单商品点击自提优惠信息
	async getmoneyInfo() {
		const {
			data: res
		} = await wepy.post('baseRest/getOrderGoodsInfo', {
			memberId: wepy.getStorageSync('userId'),
			goods_info: this.goods_info,
			address: this.addre,
			qhType: this.qhType,
			seckillGoodId: this.seckillGoodId,
			payType: this.goodInfo.payType,
			shengId: this.shengId,
			shiId: this.shiId,
			quId: this.quId,
		})
		console.log(res)
		if (res.state != 1) {
			return Toast.fail(res.message)
		}
		this.youhuiInfo = res.data
		if (res.data.manzengGoods != "") {
			this.sendsgoods = res.data.manzengGoods
		}
		this.$apply()
	}
	// 查询小区列表
	async getxiaoquList() {
		const {
			data: res
		} = await wepy.post('baseRest/findAllCommunityList')
		console.log('小区列表', res)
		if (res.state != 1) {
			//return Toast.fail('网络异常，请稍后重试')
		} else {
			if (res.data != '') {
				var ssmm = [];
				this.columns2 = [];
				this.$apply()
				for (var i = 0; i < res.data.length; i++) {
					this.columns2.push(res.data[i].name)
					ssmm.push(res.data[i])
				}
				console.log(ssmm, "vvvvvvvvvv")
				this.xiaoquList = ssmm
				this.$apply()
			} else {
				this.quyu = "请选择小区"
			}
		}
	}
	// 购物车点自提
	async getcartzitiMoney() {
		const {
			data: res
		} = await wepy.post('baseRest/getShoppingCartListPrice', {
			cart_id_list: this.cart_id_list,
			address: this.addre,
			qhType: this.qhType,
			payType: this.payType,
			memberId: wepy.getStorageSync('userId'),
			areaId:this.sanareaId
		})
		console.log(res)
		if (res.state != 1) {
			return Toast.fail(res.message)
		}
		this.cartyou = res.data
		if (res.data.manzengGoods != "") {
			this.sendsgoods = res.data.manzengGoods.substr(0, res.data.manzengGoods.length - 1)
		}
		this.$apply()

	}
	// 查询用户是否有自提地址
	async getuserId() {
		const {
			data: res
		} = await wepy.post('baseRest/findZiTiBean', {
			memberId: wepy.getStorageSync('userId'),
		})
		if (res.state == 1) {
			if (res.data.id) {
				this.userZiti = res.data
				this.quyu = this.userZiti.communityName
				this.mingzi = this.userZiti.memberName
				this.telnumber = this.userZiti.memberPhone
				this.xid = this.userZiti.communityId
				this.shengId='';
				this.shiId='';
				this.quId='';
				this.addre.id = '';
				this.addre.community = '';
				this.addre.linkPhone = '';
				this.addre.area = '';
				this.addre.building = '';
				this.addre.buildingId = '';
				this.addre.communityId = this.userZiti.communityId;
				this.addre.houseNumber = '';
				this.addre.houseNumberId = '';
				this.addre.isDefault = '';
				this.addre.areaId = '';
				this.addre.unit = '';
				this.addre.reName = '';
				this.addre.unitId = '';
				if (this.state == '1') { //单商品进入自提
					this.getmoneyInfo()
				} else { //购物车进入自提
					this.getcartzitiMoney()
				}
				this.$apply()
			} else {
				this.addre = {
					"area": "",
					"areaId": "",
					"building": "",
					"buildingId": "",
					"community": "",
					"communityId": "",
					"houseNumber": "",
					"houseNumberId": "",
					"id": "",
					"isDefault": "",
					"linkPhone": "",
					"reName": "",
					"unit": "",
					"unitId": ""
				}
				if (this.tabsp == 1) { //自提
					if (this.state == '1') { //单商品进入自提
						this.getmoneyInfo()
					} else { //购物车进入自提
						this.getcartzitiMoney()
					}
				} else if (this.tabsp == 0) { //不自提
					if (this.state == '1') { //单商品进入不自提
						this.getmoneyInfo()
					} else { //购物车进入不自提
						this.getcartzitiMoney()
					}
				}
				this.$apply()
			}
		} else {
			//return Toast.fail('网络异常')
		}
	}
	// 购物车订单列表
	async orderList() {
		const {
			data: res
		} = await wepy.post('baseRest/getShoppingCartSubList', {
			cart_id_list: this.cart_id_list,
			cart_num_list: this.cart_num_list,
		})
		console.log(res.data, '-------22222')
		if (res.state != 1) {
			return Toast.fail('生成订单失败，请稍后尝试...')
		}
		this.orderListInfo = res.data
		this.$apply()
	}
}
